}
int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags)
+ uint32_t max_factor, uint32_t flags, int (*suspend)(void))
{
PERROR("xc_linux_save not implemented\n");
return -1;
}
-static int suspend_and_state(int xc_handle, int io_fd, int dom,
- xc_dominfo_t *info,
+static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
+ int dom, xc_dominfo_t *info,
vcpu_guest_context_t *ctxt)
{
int i = 0;
- char ans[30];
- printf("suspend\n");
- fflush(stdout);
- if (fgets(ans, sizeof(ans), stdin) == NULL) {
- ERR("failed reading suspend reply");
- return -1;
- }
- if (strncmp(ans, "done\n", 5)) {
- ERR("suspend reply incorrect: %s", ans);
+ if (!(*suspend)(dom)) {
+ ERR("Suspend request failed");
return -1;
}
int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags)
+ uint32_t max_factor, uint32_t flags, int (*suspend)(int))
{
xc_dominfo_t info;
last_iter = 1;
- if (suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt)) {
+ if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
ERR("Domain appears not to have suspended");
goto out;
}
DPRINTF("Start last iteration\n");
last_iter = 1;
- if (suspend_and_state(xc_handle, io_fd, dom, &info, &ctxt)) {
+ if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
+ &ctxt)) {
ERR("Domain appears not to have suspended");
goto out;
}
* @return 0 on success, -1 on failure
*/
int xc_linux_save(int xc_handle, int fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */);
+ uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
+ int (*suspend)(int));
+
/**
* This function will restore a saved domain running Linux.
#include <err.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <stdio.h>
#include <xenguest.h>
+
+/**
+ * Issue a suspend request through stdout, and receive the acknowledgement
+ * from stdin. This is handled by XendCheckpoint in the Python layer.
+ */
+static int suspend(int domid)
+{
+ char ans[30];
+
+ printf("suspend\n");
+ fflush(stdout);
+
+ return (fgets(ans, sizeof(ans), stdin) != NULL &&
+ !strncmp(ans, "done\n", 5));
+}
+
+
int
main(int argc, char **argv)
{
max_f = atoi(argv[5]);
flags = atoi(argv[6]);
- return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags);
+ return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
}